package com.bw.zg2.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.zg2.base.BaseResult
import com.bw.zg2.base.BaseViewModel
import com.bw.zg2.bean.CartBean
import com.bw.zg2.bean.GoodsDetailBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 *
 * @ClassName: GoodsDetailViewModel
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/25 3:30 PM
 * @Version: 1.0
 */
class CartViewModel : BaseViewModel() {

    val liveDataGoodsCart = MutableLiveData<BaseResult<List<CartBean>>>()

    /**
     * 获取购物车列表
     */
    fun getCarts() {
        viewModelScope.launch {
            withContext(Dispatchers.IO) {
                liveDataGoodsCart.postValue(apiService.getGoodsCarts())
            }
        }
    }


    /**
     * 删除购物车
     * @param map Map<String, Int>
     */
    fun deleteCart(map: Map<String, String>) {
        viewModelScope.launch {
            withContext(Dispatchers.IO) {
//                liveDataDeleteGoodsCart.postValue(apiService.deleteGoodsCar(map))
            }

        }
    }
}